import Vue from "vue";
import Router from "vue-router";

// 解决重复跳转的警告
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

Vue.use(Router);
const routes = [
  {
    path: '/',
    component: () => import("@/views/Index.vue"),
    redirect: '/home',
    children: []
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login"),
  },
  {
    path: "/404",
    name: "Err404",
    component: () => import("@/views/Err404.vue"),
  },
  {
    path: "/test",
    name: "Test",
    component: () => import("@/views/test.vue"),
  },
  {
    path: "/common",
    name: "Common",
    component: () => import("@/views/layout.vue"),
    children: [
      {
        path: "appdetail",
        name: "Appdetail",
        component: () => import("@/views/application/detail/detail"),
        meta: {
          title: '应用详情', activeMenu: '/app'
        }
      },
      {
        path: "updateapp",
        name: "UpdateApp",
        component: () => import("@/views/application/update/updateApp"),
        meta: {
          title: '修改应用信息', activeMenu: '/app'
        }
      },
      {
        path: "appbasic",
        name: "AppBasic",
        component: () => import("@/views/application/basic/basicOther"),
        meta: {
          title: '应用附属信息', activeMenu: '/app'
        }
      },
      {
        path: "apptask",
        name: "AppTask",
        component: () => import("@/views/application/tasks"),
        meta: {
          title: '任务管理', activeMenu: '/app'
        }
      },
      {
        path: "apptrail",
        name: "AppTrail",
        component: () => import("@/views/application/data/trail"),
        meta: {
          title: '轨迹', activeMenu: '/app'
        }
      }
    ]
  },
  {
    path: "/fun",
    name: "Fun",
    component: () => import("@/views/layout.vue"),
    children: [
      {
        path: "funlist",
        name: "FunList",
        component: () => import("@/views/component/funlist/funlist"),
        meta: {
          title: '函数列表', activeMenu: '/component'
        }
      },
      {
        path: "addfun",
        name: "AddFun",
        component: () => import("@/views/component/funlist/addfun"),
        meta: {
          title: '新增函数', activeMenu: '/component'
        }
      },
    ]
  }
];

const createRouter = () => new Router({
  //激活类名
  linkActiveClass: "on current-page",
  linkExactActiveClass: "",
  mode: "hash",
  routes,
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router;
